package com.bankcomm.ui;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.MKAddrInfo;
import com.baidu.mapapi.MKBusLineResult;
import com.baidu.mapapi.MKDrivingRouteResult;
import com.baidu.mapapi.MKPlanNode;
import com.baidu.mapapi.MKPoiResult;
import com.baidu.mapapi.MKSearch;
import com.baidu.mapapi.MKSearchListener;
import com.baidu.mapapi.MKSuggestionResult;
import com.baidu.mapapi.MKTransitRouteResult;
import com.baidu.mapapi.MKWalkingRouteResult;
import com.baidu.mapapi.MapController;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.Overlay;
import com.baidu.mapapi.OverlayItem;
import com.baidu.mapapi.RouteOverlay;
import com.baidu.mapapi.TransitOverlay;
import com.bankcomm.BankcommApplication;
import com.bankcomm.R;

import com.bankcomm.bean.BranchPoint;
import com.bankcomm.bean.NodeInfo;
import com.bankcomm.bean.NodeListInfo;
import com.bankcomm.bean.NodeSearch;
import com.bankcomm.bean.OnlineBooking;
import com.bankcomm.bean.PageInfo;
import com.bankcomm.common.ConfigManager;
import com.bankcomm.common.LPMid;
import com.bankcomm.location.BaiduLocation;
import com.bankcomm.location.MyLocationOverlayItem;
import com.bankcomm.location.MyPoiOverlayItem;
import com.bankcomm.net.http.HttpConnection;
import com.bankcomm.ui.adapter.ArrayWheelAdapter;
import com.bankcomm.ui.adapter.NodeInfoAdapter;
import com.bankcomm.util.Base64;
import com.bankcomm.util.DensityUtil;
import com.bankcomm.util.LPUtils;
import com.bankcomm.ui.specialwidget.MostPopShopGallery;
import com.bankcomm.ui.specialwidget.MyCityChoose;
import com.bankcomm.ui.specialwidget.MyIXListView;
import com.bankcomm.ui.specialwidget.OnWheelChangedListener;
import com.bankcomm.ui.specialwidget.WheelView;
import com.bankcomm.ui.specialwidget.MyIXListView.IXListViewListener;
import com.bankcomm.ui.specialwidget.MySelect;
import com.bankcomm.ui.views.LPBottomBar;
import com.rytong.tools.httpconnect.WaitDialog;
import com.rytong.tools.httpconnect.WaitDialog.Task;
import com.rytong.tools.utils.LPToastUtil;
import com.rytong.tools.utils.Utils;

/**
 * 位置服务页面
 * 
 */
public class LocationServiceActivity extends BOCMyMapViewActivity implements
		IXListViewListener {

	/** 应用管理对象 */
	private BankcommApplication app = null;

	private LPMid mid = null;

	/** 位置服务右侧布局视图 */
	private LinearLayout rightLayout;

	/** 显示地图的View */
	public MapView mMapView = null;

	/** 处理地图移动和缩放的工具类 */
	private MapController mapController = null;

	/** 搜索服务 */
	private MKSearch mSearch = null;

	/** 当前我的位置偏移前后经纬度 */
	private double currentLon = 0D;
	private double currentLat = 0D;
	private double excursionCurrLon = 0D;
	private double excursionCurrLat = 0D;

	/** 图层集合 */
	MyPoiOverlayItem myGeoOverlayItem;

	/** 临时图层集合, 供返回用 */
	MyPoiOverlayItem tempGeoOverlayItem;

	/** 标记图标 */
	private Drawable myMarker;
	private Drawable poiMarker;

	/** 定位图标 */
	private ImageView locationIV;

	/** 周边搜索图标 */
	private ImageView aroundIV;

	/** 周边搜索分类PW */
	private PopupWindow aroundPW;

	/** 滚轮视图 */
	private View wheelView;
	private int aroundBigItem;
	private int aroundSmallItem;

	/** 待搜索的类别 */
	private String type = null;

	/** 点击mark时弹出的气泡View */
	public View mPopView;

	/** 初始化地图布局页面 */
	private RelativeLayout bmapRL;

	/** 栈键值, 默认为周边搜索 */
	private String stackKey = "searchAround";

	/** 页面栈集合 */
	private HashMap<String, Stack<PageInfo>> pageInfos = new HashMap<String, Stack<PageInfo>>();

	/** 定位PD */
	ProgressDialog locationDialog;

	/** 网点偏移PD */
	ProgressDialog excursionDialog;

	/** 网点查询PD */
	ProgressDialog getBranchsPD;

	/** 可显示异常信息PD */
	ProgressDialog canShowErrorPD;

	/** 网点查询结果值 */
	public int successState = 0;
	public static final int NO_QUERY_RESULT = 4;
	public static final int CHANGE_TYPE = 5;
	public static final int GET_BRANCH_DETAIL_SUCCESS = 6;

	/** 偏移常量值 */
	public int excursionConstant = 0;
	public static final int LOCATION_EXCURSION = 1;
	public static final int BRANCH_EXCURSION = 2;
	public static final int ROUTE_EXCURSION = 3;
	public double excursionedBranchLon = 0D;
	public double excursionedBranchLat = 0D;

	/** 路线常量值 */
	public int routeConstant = 0;
	public static final int DRIVING = 1;
	public static final int TRANSIT = 2;
	public static final int WALKING = 3;

	/** 商户LOGO */
	MostPopShopGallery merchantLogoImage;

	/** 滚轮常量值 */
	public int wheelConstant = 0;
	public static final int AROUND_TYPE = 1;
	public static final int MERCHANT_REGION = 2;
	public static final int MERCHANT_TYPE = 3;

	/** 下拉刷新与下拉加载更多Handler */
	private Handler ixHandler;

	/** 特惠商户"所有地区"按钮 */
	Button allRegionBtn;
	/** 特惠商户"所有分类"按钮 */
	Button allTypeBtn;

	/** 特惠商户主视图 */
	View merchantMainView;
	/** 特惠商户搜索文本 */
	EditText merchantET;
	/** 特惠商户列表 */
	MyIXListView merchantLV;
	/** 特惠商户列表无数据文本 */
	TextView noResTV;

	/** 网点查询url体, 供加载更多使用 */
	String nodeSearchUrlBody;
	/** 网点列表 */
	MyIXListView nodeSearchLV;
	/** 网点列表Adapter */
	NodeInfoAdapter nodeInfoAdapter;
	/** 网点查询类型 */
	MySelect mySelect;

	// 标题内容

	// 标题Logo

	// 是否人为取消定位对话框
	boolean isCancelLocationDialog = false;

	private int width;

	private TextView textTitle;

	private BaiduLocation locationService;

	private Button backBtn;

	private Button homeBtn;

	private LPBottomBar bottomLayout;

	private RelativeLayout topLayout;

	private String currAct;

	private void initTopAndBottomHeight() {
		LPUtils.scaledTHeightRel(topLayout);
		LPUtils.setTitleButtonWH(backBtn);
		LPUtils.setTitleButtonWH(homeBtn);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		BankcommApplication.getInstance().addActivity(this);
		setContentView(R.layout.locationservice);
		bottomLayout = (LPBottomBar) findViewById(R.id.bottom_bar);
		bottomLayout.setSelectTab(1);

		topLayout = (RelativeLayout) findViewById(R.id.linearLayout1);
		
		WindowManager window = this.getWindowManager();
		width = window.getDefaultDisplay().getWidth();

		// 初始化LPMid
		mid = LPMid.getInstance();
		String str = getIntent().getStringExtra("str");
		currAct = str;
		ixHandler = new Handler();

		// 初始化栈
		pageInfos.put("searchAround", new Stack<PageInfo>());
		pageInfos.put("specialShop", new Stack<PageInfo>());
		pageInfos.put("nodeSearch", new Stack<PageInfo>());

		// 初始化POI图标
		myMarker = getResources().getDrawable(R.drawable.baidu_map_me);
		poiMarker = getResources().getDrawable(R.drawable.baidu_map_poi);

		// 重置
		isCancelLocationDialog = false;

		// 右侧列表
		rightLayout = (LinearLayout) findViewById(R.id.lsRightLayout);
		bmapRL = (RelativeLayout) findViewById(R.id.bmapRL);
		// -------------------------------------------------------------------百度地图
		// start
		app = (BankcommApplication) this.getApplication();
		if (app.mBMapMan == null) {
			app.mBMapMan = new BMapManager(getApplication());
			app.mBMapMan.init(app.mStrKey,
					new BankcommApplication.MyGeneralListener());
		}
		app.mBMapMan.start();
		// 如果使用地图SDK，请初始化地图Activity
		super.initMapActivity(app.mBMapMan);

		mMapView = (MapView) findViewById(R.id.bmapView);
		mMapView.setClickable(true);
		// 不显示缩放控件
		mMapView.setBuiltInZoomControls(true);
		// 设置在缩放动画过程中绘制overlay，默认为不绘制。
		mMapView.setDrawOverlayWhenZooming(true);

		mapController = mMapView.getController();
		mapController.setZoom(17);

		mSearch = new MKSearch();
		mSearch.init(app.mBMapMan, mkSearchListener);
		//
		// // 弹出的气泡View
		mPopView = getLayoutInflater().inflate(R.layout.map_pop, null);
		mMapView.addView(mPopView);
		mPopView.setVisibility(View.GONE);
		mPopView.setOnClickListener(popClickListener);

		// 初始化POI集合
		myGeoOverlayItem = new MyPoiOverlayItem(this, poiMarker);
		tempGeoOverlayItem = new MyPoiOverlayItem(this, poiMarker);

		// -------------------------------------------------------------------百度地图
		// end

		// 初始化进度对话框
		initProgressDialog();
		textTitle = (TextView) findViewById(R.id.txtTitle);

		locationService = BaiduLocation.getInstance();

		// 把当前页面放至栈
		pushPageToStack(bmapRL, stackKey);

		backBtn = (Button) findViewById(R.id.backtitle);
		homeBtn = (Button) findViewById(R.id.hometitle);
		backBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				keybackPressed();
			}
		});
		homeBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				exitApp();
			}
		});
		initTopAndBottomHeight();
		// 周边搜索
		if ("search_around".equals(str)) {
			textTitle.setText(getString(R.string.around_search));
			gotoSearchAroundView();
		}
		// 特惠商户
		// else if ("2".equals(str)) {
		// gotoSpecialShopView();
		// }
		// 网点查询
		else if ("one_node_query".equals(str)) {
			textTitle.setText(getString(R.string.node_query));
			gotoNodeSearch();
		}
	}

	private View.OnClickListener locationIVClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			// 移动到我的位置
			moveToMyLocation();
		}
	};

	private View.OnClickListener aroundIVClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			// 显示滚轮弹出框
			if (mid.bigClass != null && mid.bigClass.length > 0) {
				showPopWin();
			}
		}
	};

	private View.OnClickListener popClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			mPopView.setVisibility(View.GONE);

			// 2.加入新的视图
			if (mid.currentBranchBody != null
					&& mid.currentBranchBody.length() > 0) {
				mid.waitDialog_.addFgTask(LocationServiceActivity.this, null,
						0, 0, 0, new WaitDialog.Task(0) {
							String branchType = null;
							String branchResult = null;

							@Override
							public void run(WaitDialog dlg) throws Exception {
								// Message getBranchDetailMsg = new Message();
								// getBranchDetailMsg.what = 1;
								// getBranchsHandler
								// .sendMessage(getBranchDetailMsg);
								// markCode=ABBM936&flag=2
								// String[] currentBranchBodyArr =
								// mid.currentBranchBody
								// .split("=");
								// branchType =
								// currentBranchBodyArr[currentBranchBodyArr.length
								// - 2];
								int indexsq = mid.currentBranchBody
										.indexOf("=");
								branchType = mid.currentBranchBody.substring(0,
										indexsq);

								String branchUrl = null;
								// 普通网点
								if ("markCode".equals(branchType)) {
									branchUrl = ConfigManager.SERVER_URI
											+ ConfigManager.MAP_GET_NODE_DETAIL;
								}
								// 特惠商户
								else if ("merId".equals(branchType)) {
									branchUrl = ConfigManager.SERVER_URI
											+ ConfigManager.MAP_GET_MERCHANT_DETAIL;
								}
								branchResult = (String) LPMid.getInstance().hm_
										.sendPostRequest(branchUrl
												+ mid.currentBranchBody, null,
												this, null, null);
								Utils.printOutToConsole(branchResult);
							}

							public void onSuccess(WaitDialog dlg) {
								Message getBranchDetailMsg = new Message();
								getBranchDetailMsg.what = 2;

								String branchCoord = null;
								if (branchResult != null
										&& branchResult.length() > 0) {
									// 普通网点
									if ("markCode".equals(branchType)) {
										branchCoord = getNodeDetailInfo(
												branchResult, branchCoord);
									}
									// // 特惠商户
									else if ("merId".equals(branchType)) {
										branchCoord = getMerchantDetailInfo(
												branchResult, branchCoord);
									}
									getBranchDetailMsg.obj = branchCoord;
									successState = GET_BRANCH_DETAIL_SUCCESS;
									getBranchsHandler
											.sendMessage(getBranchDetailMsg);
								}

								super.onSuccess(dlg);
							}

							public void onFailure(WaitDialog dlg) {
								Utils.printOutToConsole(getErrMsg());
								Message getBranchDetailMsg = new Message();
								getBranchDetailMsg.what = 3;
								getBranchDetailMsg.obj = errmsg_;
								getBranchsHandler
										.sendMessage(getBranchDetailMsg);

								super.onFailure(dlg);
							};
						});
			}
		}
	};

	private String getNodeDetailInfo(String nodeDetailResult, String branchCoord) {
		try {
			JSONObject branchResultJO = new JSONObject(nodeDetailResult);
			final String name = branchResultJO.getString("name");
			final String address = branchResultJO.getString("address");
			final String phone = branchResultJO.getString("phone");
			final String businessTime = branchResultJO
					.getString("businessTime");
			branchCoord = branchResultJO.getString("coord");

			final View branchDetail = getLayoutInflater().inflate(
					R.layout.branch_detail, null);
			// 名称
			TextView nameText = (TextView) branchDetail
					.findViewById(R.id.nameText);
			nameText.getPaint().setFakeBoldText(true);
			nameText.setText(getString(R.string.branch_name) + name);

			// 地址
			TextView addressText = (TextView) branchDetail
					.findViewById(R.id.addressText);
			addressText.setText(getString(R.string.branch_address) + address);
			ImageView addressImage = (ImageView) branchDetail
					.findViewById(R.id.addressImage);
			addressImage.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					if (excursionedBranchLon == 0.0) {
						showErrorCastDialog(LocationServiceActivity.this
								.getString(R.string.locationError));
					} else {
						generateView();
						showMyLocation(excursionedBranchLat,
								excursionedBranchLon, poiMarker);
					}
				}
			});

			// 电话
			final TextView phoneText = (TextView) branchDetail
					.findViewById(R.id.phoneText);
			phoneText.setText(getString(R.string.branch_phone) + phone);

			ImageView callImage = (ImageView) branchDetail
					.findViewById(R.id.callImage);
			callImage.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					if (!phone.equals("") && phone != null) {
						initDelDialog(getString(R.string.branch_phone) + phone);
					}

				}
			});

			// 营业时间
			TextView businessTimeText = (TextView) branchDetail
					.findViewById(R.id.businessTimeText);
			businessTimeText.setText(getString(R.string.branch_business_time)
					+ businessTime);

			// 按钮
			Button bookOnlineBtn = (Button) branchDetail
					.findViewById(R.id.bookOnline);
			LinearLayout bottomBtnLayout = (LinearLayout) branchDetail
					.findViewById(R.id.bottomBtnLayout);
			// 有网点预约功能
			if (branchResultJO.has("action")) {
				bottomBtnLayout.setVisibility(View.VISIBLE);

				final String action = branchResultJO.getString("action");
				final String branchNo = branchResultJO.getString("branchNo");
				final String ambegin = branchResultJO.getString("ambegin");
				final String amend = branchResultJO.getString("amend");
				final String pmbegin = branchResultJO.getString("pmbegin");
				final String pmend = branchResultJO.getString("pmend");
				final String lonLat = branchCoord;

				String systime = branchResultJO.getString("systime");
				String queue = branchResultJO.getString("queue");
				JSONArray queueJA = new JSONArray(queue);

				LinearLayout nodeBookLayout = (LinearLayout) branchDetail
						.findViewById(R.id.nodeBookLayout);
				TextView noResTV = (TextView) branchDetail
						.findViewById(R.id.noResTV);

				// 有网点预约
				if (queueJA.length() > 0) {
					nodeBookLayout.setVisibility(View.VISIBLE);
					noResTV.setVisibility(View.GONE);

					((TextView) branchDetail
							.findViewById(R.id.nodeBookQueueInfo)).getPaint()
							.setFakeBoldText(true);
					TextView nodeBookQueueData = (TextView) branchDetail
							.findViewById(R.id.nodeBookQueueData);
					nodeBookQueueData.setText(systime);
					((TextView) branchDetail
							.findViewById(R.id.nodeBookCustomType)).getPaint()
							.setFakeBoldText(true);
					((TextView) branchDetail
							.findViewById(R.id.nodeBookQueueCount)).getPaint()
							.setFakeBoldText(true);

					LinearLayout nodeBookQueueInfoLayout = (LinearLayout) branchDetail
							.findViewById(R.id.nodeBookQueueInfoLayout);
					for (int i = 0; i < queueJA.length(); i++) {
						JSONObject queueJO = (JSONObject) queueJA.get(i);
						String queueName = queueJO.getString("queuename");
						String queueSize = queueJO.getString("queuesize");

						LinearLayout layout = new LinearLayout(
								LocationServiceActivity.this);
						LayoutParams layoutParams = new LayoutParams(
								LayoutParams.FILL_PARENT,
								LayoutParams.WRAP_CONTENT);
						int margin = DensityUtil.dip2px(
								LocationServiceActivity.this, 7);
						layoutParams.leftMargin = margin;
						layoutParams.topMargin = margin;
						layoutParams.rightMargin = margin;
						layoutParams.bottomMargin = margin;
						layout.setLayoutParams(layoutParams);
						layout.setOrientation(LinearLayout.HORIZONTAL);

						TextView customTypeText = new TextView(
								LocationServiceActivity.this);
						int width = DensityUtil.dip2px(
								LocationServiceActivity.this, 100);
						LayoutParams customTypeLayoutParam = new LayoutParams(
								width, LayoutParams.WRAP_CONTENT);
						customTypeText.setLayoutParams(customTypeLayoutParam);
						customTypeText.setText(queueName);
						customTypeText.setTextColor(Color.rgb(127, 157, 227));
						layout.addView(customTypeText);

						TextView queueCountText = new TextView(
								LocationServiceActivity.this);
						LayoutParams queueCountLayoutParam = new LayoutParams(
								LayoutParams.WRAP_CONTENT,
								LayoutParams.WRAP_CONTENT);
						queueCountText.setLayoutParams(queueCountLayoutParam);
						queueCountText.setText(queueSize);
						queueCountText.setTextColor(Color.rgb(127, 157, 227));
						layout.addView(queueCountText);

						nodeBookQueueInfoLayout.addView(layout);

						View view = new View(LocationServiceActivity.this);
						view
								.setBackgroundResource(R.drawable.horizontal_separation_line);
						view.setLayoutParams(new LayoutParams(
								LayoutParams.FILL_PARENT, 1));
						nodeBookQueueInfoLayout.addView(view);
					}
				}
				// 无网点预约, 提示信息
				else {
					nodeBookLayout.setVisibility(View.GONE);
					noResTV.setVisibility(View.VISIBLE);
					noResTV.getPaint().setFakeBoldText(true);
				}

				bookOnlineBtn.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						mid.waitDialog_.addFgTask(LocationServiceActivity.this,
								null, 0, 0, 0, new WaitDialog.Task(0) {
									HashMap<String, OnlineBooking> onlineBookingMap;

									@Override
									public void run(WaitDialog dlg)
											throws Exception {
										// Message msg = new Message();
										// msg.what = 1;
										// canShowErrorHandler.sendMessage(msg);
										String onlineBookingBody = "branchNo="
												+ Utils
														.escapeURIComponent(branchNo)
												+ "&title="
												+ Utils
														.escapeURIComponent(name)
												+ "&addr="
												+ Utils
														.escapeURIComponent(address)
												+ "&tel="
												+ Utils
														.escapeURIComponent(phone
																.trim())
												+ "&oTime="
												+ Utils
														.escapeURIComponent(businessTime)
												+ "&ambegin="
												+ Utils
														.escapeURIComponent(ambegin)
												// + "&amend=" +
												// Utils.escapeURIComponent(amend)
												+ "&pmbegin="
												+ Utils
														.escapeURIComponent(pmbegin)
												+ "&pmend="
												+ Utils
														.escapeURIComponent(pmend)
												+ "&lon="
												+ lonLat.split(",")[0]
												+ "&lat="
												+ lonLat.split(",")[1];
										onlineBookingMap = BankcommApplication.server
												.getOnlineBookingData(
														ConfigManager.SERVER_URI
																+ "/" + action,
														onlineBookingBody);
									}

									public void onSuccess(WaitDialog dlg) {
										Message msg = new Message();
										msg.what = 2;

										// 2. 显示界面
										LocationServiceActivity.this
												.runOnUiThread(new Runnable() {

													@Override
													public void run() {
														final View onlineBookingView = getLayoutInflater()
																.inflate(
																		R.layout.online_booking,
																		null);

														LinearLayout onlineBookingLayout = (LinearLayout) onlineBookingView
																.findViewById(R.id.onlineBookingLayout);
														TextView noResTV = (TextView) onlineBookingView
																.findViewById(R.id.noResTV);
														if (onlineBookingMap
																.get("error") != null) {
															onlineBookingLayout
																	.setVisibility(View.GONE);
															noResTV
																	.setVisibility(View.VISIBLE);
															noResTV
																	.setText(onlineBookingMap
																			.get(
																					"error")
																			.getData());
															noResTV
																	.getPaint()
																	.setFakeBoldText(
																			true);
														} else {
															onlineBookingLayout
																	.setVisibility(View.VISIBLE);
															noResTV
																	.setVisibility(View.GONE);

															// 网点名称
															final TextView branchNameTV = (TextView) onlineBookingView
																	.findViewById(R.id.branchName);
															branchNameTV
																	.setText(onlineBookingMap
																			.get(
																					"nodeName")
																			.getData());

															// 预约日期
															final String bookingDate = onlineBookingMap
																	.get(
																			"bookingData")
																	.getData();
															final TextView bookingDataTV = (TextView) onlineBookingView
																	.findViewById(R.id.bookingDate);
															bookingDataTV
																	.setText(bookingDate
																			+ " "
																			+ LPUtils
																					.getWeekDay(bookingDate));

															// 预约开始时间
															LinkedHashMap<String, String> typeMap = new LinkedHashMap<String, String>();
															try {
																JSONArray typeJA = new JSONArray(
																		onlineBookingMap
																				.get(
																						"beginBookingData")
																				.getData());
																for (int i = 0; i < typeJA
																		.length(); i++) {

																	JSONObject typeJO = (JSONObject) typeJA
																			.get(i);
																	typeMap
																			.put(
																					typeJO
																							.getString("name"),
																					typeJO
																							.getString("value"));
																}
															} catch (JSONException e) {
																e
																		.printStackTrace();
															}
															final MySelect myBeginBookingDataSelect = (MySelect) onlineBookingView
																	.findViewById(R.id.beginBookingData);
															myBeginBookingDataSelect
																	.initWeelSelect(typeMap);

															// 预约手机
															final EditText bookingPhoneET = (EditText) onlineBookingView
																	.findViewById(R.id.bookingPhone);
															BitmapDrawable bd = (BitmapDrawable) LocationServiceActivity.this
																	.getResources()
																	.getDrawable(
																			R.drawable.small_2);
															bookingPhoneET
																	.setCompoundDrawablesWithIntrinsicBounds(
																			0,
																			0,
																			R.drawable.small_2,
																			0);
															final int padLeft = bd
																	.getIntrinsicWidth()
																	+ bookingPhoneET
																			.getPaddingLeft();
															bookingPhoneET
																	.setOnTouchListener(new OnTouchListener() {
																		@Override
																		public boolean onTouch(
																				View view,
																				MotionEvent event) {
																			float curX = event
																					.getX();
																			switch (event
																					.getAction()) {
																			case MotionEvent.ACTION_UP:
																				if (curX > bookingPhoneET
																						.getWidth()
																						- padLeft) {
																					LocationServiceActivity.this
																							.setPhoneLPTextField(bookingPhoneET);
																					LocationServiceActivity.this
																							.getPeopleConnects(LocationServiceActivity.this);
																					InputMethodManager iim = (InputMethodManager) LocationServiceActivity.this
																							.getSystemService(Context.INPUT_METHOD_SERVICE);
																					if (iim
																							.isActive()
																							&& LocationServiceActivity.this
																									.getCurrentFocus() != null) {
																						iim
																								.hideSoftInputFromWindow(
																										LocationServiceActivity.this
																												.getCurrentFocus()
																												.getWindowToken(),
																										InputMethodManager.HIDE_NOT_ALWAYS);
																					}
																				}
																				break;
																			default:
																				break;
																			}
																			return false;
																		}
																	});

															bookingPhoneET
																	.setText(onlineBookingMap
																			.get(
																					"bookingPhone")
																			.getData());

															// 确定
															Button bookOnlineSureBtn = (Button) onlineBookingView
																	.findViewById(R.id.bookOnlineSure);
															bookOnlineSureBtn
																	.setOnClickListener(new View.OnClickListener() {

																		@Override
																		public void onClick(
																				View v) {
																			final String bookingPhone = bookingPhoneET
																					.getText()
																					.toString();

																			if (bookingPhone != null
																					&& !""
																							.equals(bookingPhone)) {
																				mid.waitDialog_
																						.addFgTask(
																								LocationServiceActivity.this,
																								null,
																								0,
																								0,
																								0,
																								new WaitDialog.Task(
																										0) {
																									String onlineBookingRes = null;

																									@Override
																									public void run(
																											WaitDialog dlg)
																											throws Exception {
																										// Message
																										// msg
																										// =
																										// new
																										// Message();
																										// msg.what
																										// =
																										// 1;
																										// canShowErrorHandler
																										// .sendMessage(msg);

																										// 拼装请求参数
																										String onlineBookingSureUrl = "branchNo="
																												+ Utils
																														.escapeURIComponent(branchNo)
																												+ "&branchName="
																												+ Utils
																														.escapeURIComponent(name)
																												+ "&branchAddress="
																												+ Utils
																														.escapeURIComponent(address)
																												+ "&branchPhone="
																												+ Utils
																														.escapeURIComponent(phone
																																.trim())
																												+ "&branchBussiness="
																												+ Utils
																														.escapeURIComponent(businessTime)
																												+ "&bookingDate="
																												+ Utils
																														.escapeURIComponent(bookingDate)
																												+ "&bookingTime="
																												+ Utils
																														.escapeURIComponent(myBeginBookingDataSelect
																																.getValue())
																												+ "&bookingMobile="
																												+ Utils
																														.escapeURIComponent(bookingPhone)
																												+ "&lon="
																												+ lonLat
																														.split(",")[0]
																												+ "&lat="
																												+ lonLat
																														.split(",")[1];
																										onlineBookingRes = (String) LPMid
																												.getInstance().hm_
																												.sendPostRequest(
																														ConfigManager.SERVER_URI
																																+ ConfigManager.MAP_DO_BOOKING,
																														onlineBookingSureUrl,
																														this,
																														null,
																														null);
																									};

																									public void onSuccess(
																											WaitDialog dlg) {
																										Message msg = new Message();
																										msg.what = 2;

																										// 2.
																										// 显示页面
																										if (onlineBookingRes != null
																												&& onlineBookingRes
																														.length() > 0) {
																											try {
																												final JSONObject onlineBookingResJO = new JSONObject(
																														onlineBookingRes);
																												// 撤销
																												if (onlineBookingResJO
																														.has("action")) {
																													final View onlineBookingDisfrockView = getLayoutInflater()
																															.inflate(
																																	R.layout.online_booking_disfrock,
																																	null);
																													String disfrockMsg = onlineBookingResJO
																															.getString("msg");
																													TextView disfrockTV = (TextView) onlineBookingDisfrockView
																															.findViewById(R.id.disfrockTV);
																													disfrockTV
																															.setText(disfrockMsg);

																													String cancelBtName = onlineBookingResJO
																															.getString("cancelBtName");
																													Button bookOnlineDisfrockBtn = (Button) onlineBookingDisfrockView
																															.findViewById(R.id.bookOnlineDisfrockBtn);
																													bookOnlineDisfrockBtn
																															.setText(cancelBtName);

																													final String cancelMsg = onlineBookingResJO
																															.getString("cancelMsg");
																													final String confirmBtName = onlineBookingResJO
																															.getString("confirmBtName");
																													bookOnlineDisfrockBtn
																															.setOnClickListener(new View.OnClickListener() {

																																@Override
																																public void onClick(
																																		View v) {
																																	// 弹出提示框
																																	AlertDialog.Builder builder = new AlertDialog.Builder(
																																			LocationServiceActivity.this);
																																	builder
																																			.setTitle(getString(R.string.quit_prompt));
																																	builder
																																			.setMessage(cancelMsg);
																																	builder
																																			.setPositiveButton(
																																					confirmBtName,
																																					new DialogInterface.OnClickListener() {
																																						public void onClick(
																																								DialogInterface dialog,
																																								int which) {
																																							mid.waitDialog_
																																									.addFgTask(
																																											LocationServiceActivity.this,
																																											null,
																																											0,
																																											0,
																																											0,
																																											new WaitDialog.Task(
																																													0) {
																																												String onlineBookingDisfrockRes = null;

																																												@Override
																																												public void run(
																																														WaitDialog dlg)
																																														throws Exception {
																																													// Message
																																													// msg
																																													// =
																																													// new
																																													// Message();
																																													// msg.what
																																													// =
																																													// 1;
																																													// canShowErrorHandler
																																													// .sendMessage(msg);

																																													// 拼装请求参数
																																													String action = onlineBookingResJO
																																															.getString("action");
																																													String bookingNo = onlineBookingResJO
																																															.getString("bookingNo");
																																													onlineBookingDisfrockRes = (String) LPMid
																																															.getInstance().hm_
																																															.sendPostRequest(
																																																	ConfigManager.SERVER_URI
																																																			+ action,
																																																	"bookingNo="
																																																			+ bookingNo,
																																																	this,
																																																	null,
																																																	null);
																																												}

																																												public void onSuccess(
																																														WaitDialog dlg) {
																																													Message msg = new Message();
																																													msg.what = 2;

																																													final View onlineBookingDisfrockResView = getLayoutInflater()
																																															.inflate(
																																																	R.layout.online_booking_disfrock_result,
																																																	null);
																																													try {
																																														TextView disfrockResTV = (TextView) onlineBookingDisfrockResView
																																																.findViewById(R.id.disfrockResTV);
																																														JSONObject onlineBookingDisfrockResJO = new JSONObject(
																																																onlineBookingDisfrockRes);
																																														String onlineBookingDisfrockResMsg = onlineBookingDisfrockResJO
																																																.getString("msg");
																																														disfrockResTV
																																																.setText(onlineBookingDisfrockResMsg);
																																													} catch (JSONException e) {
																																														e
																																																.printStackTrace();
																																													}

																																													LocationServiceActivity.this
																																															.runOnUiThread(new Runnable() {
																																																@Override
																																																public void run() {
																																																	// 1.移除右侧View
																																																	rightLayout
																																																			.removeAllViews();

																																																	rightLayout
																																																			.addView(onlineBookingDisfrockResView);
																																																}
																																															});

																																													// 把当前页面放至栈
																																													pushPageToStack(
																																															onlineBookingDisfrockResView,
																																															stackKey);

																																													canShowErrorHandler
																																															.sendMessage(msg);
																																													super
																																															.onSuccess(dlg);
																																												};

																																												public void onFailure(
																																														WaitDialog dlg) {
																																													Utils
																																															.printOutToConsole(getErrMsg());
																																													Message msg = new Message();
																																													msg.what = 3;
																																													msg.obj = errmsg_;
																																													canShowErrorHandler
																																															.sendMessage(msg);

																																													super
																																															.onFailure(dlg);
																																												};
																																											});
																																						}
																																					});
																																	builder
																																			.setNegativeButton(
																																					getString(R.string.cancel),
																																					null);
																																	builder
																																			.setCancelable(false);
																																	builder
																																			.create()
																																			.show();
																																}
																															});

																													LocationServiceActivity.this
																															.runOnUiThread(new Runnable() {
																																@Override
																																public void run() {
																																	// 1.移除右侧View
																																	rightLayout
																																			.removeAllViews();

																																	rightLayout
																																			.addView(onlineBookingDisfrockView);
																																}
																															});

																													// 把当前页面放至栈
																													pushPageToStack(
																															onlineBookingDisfrockView,
																															stackKey);
																												}
																												// 成功、失败页面
																												else {
																													final View onlineBookingResView = getLayoutInflater()
																															.inflate(
																																	R.layout.online_booking_result,
																																	null);
																													String bkRes = onlineBookingResJO
																															.getString("bkRes");
																													TextView resTV = (TextView) onlineBookingResView
																															.findViewById(R.id.resTV);
																													resTV
																															.setText(bkRes);

																													String bkMsg = onlineBookingResJO
																															.getString("bkMsg");
																													TextView resExplainTV = (TextView) onlineBookingResView
																															.findViewById(R.id.resExplainTV);
																													resExplainTV
																															.setText(bkMsg);

																													LocationServiceActivity.this
																															.runOnUiThread(new Runnable() {
																																@Override
																																public void run() {
																																	// 1.移除右侧View
																																	rightLayout
																																			.removeAllViews();

																																	rightLayout
																																			.addView(onlineBookingResView);
																																}
																															});

																													// 把当前页面放至栈
																													pushPageToStack(
																															onlineBookingResView,
																															stackKey);
																												}
																											} catch (Exception e) {
																												e
																														.printStackTrace();
																											}
																										}

																										canShowErrorHandler
																												.sendMessage(msg);
																										super
																												.onSuccess(dlg);
																									};

																									public void onFailure(
																											WaitDialog dlg) {
																										Utils
																												.printOutToConsole(getErrMsg());
																										Message msg = new Message();
																										msg.what = 3;
																										msg.obj = errmsg_;
																										canShowErrorHandler
																												.sendMessage(msg);

																										super
																												.onFailure(dlg);
																									};
																								});
																			}
																			// 若预约手机号码为空,
																			// 提示
																			else {
																				showErrorCastDialog(getString(R.string.booking_phone_error));
																			}
																		}
																	});
														}

														LocationServiceActivity.this
																.runOnUiThread(new Runnable() {

																	@Override
																	public void run() {
																		// 1.移除右侧View
																		rightLayout
																				.removeAllViews();

																		rightLayout
																				.addView(onlineBookingView);
																	}
																});

														// 把当前页面放至栈
														pushPageToStack(
																onlineBookingView,
																stackKey);
													}
												});

										canShowErrorHandler.sendMessage(msg);
										super.onSuccess(dlg);
									}

									public void onFailure(WaitDialog dlg) {
										Utils.printOutToConsole(getErrMsg());
										Message msg = new Message();
										msg.what = 3;
										msg.obj = errmsg_;
										canShowErrorHandler.sendMessage(msg);

										super.onFailure(dlg);
									};
								});
					}
				});
			} else {
				bottomBtnLayout.setVisibility(View.GONE);
			}

			LocationServiceActivity.this.runOnUiThread(new Runnable() {

				@Override
				public void run() {
					// 1.移除右侧View
					rightLayout.removeAllViews();

					rightLayout.addView(branchDetail);
				}
			});

			// 把当前页面放至栈
			pushPageToStack(branchDetail, stackKey);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return branchCoord;
	}

	public void generateView() {
		// 1.移除右侧View
		rightLayout.removeAllViews();

		// 2.加入新的视图
		// 如果使用地图SDK，请初始化地图Activity
		LocationServiceActivity.this.initMapActivity(app.mBMapMan);
		ViewParent parent_ = mMapView.getParent();
		if (null != parent_) {
			((RelativeLayout) parent_).removeView(mMapView);
		}
		// 清除所有的Overlay
		mMapView.getOverlays().clear();
		// 若气泡显示, 则使之隐藏
		if (mPopView.getVisibility() == View.VISIBLE) {
			mPopView.setVisibility(View.GONE);
		}
		rightLayout.addView(mMapView);

		// 把当前页面放至栈
		pushPageToStack(mMapView, stackKey);
	}

	private void initProgressDialog() {
		locationDialog = new ProgressDialog(this);
		locationDialog.setTitle(getString(R.string.alert));
		locationDialog.setMessage(getString(R.string.location_explain));
		locationDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		locationDialog.setCanceledOnTouchOutside(false);
		locationDialog
				.setOnCancelListener(new DialogInterface.OnCancelListener() {

					@Override
					public void onCancel(DialogInterface dialog) {
						isCancelLocationDialog = true;
					}
				});

		excursionDialog = new ProgressDialog(this);
		excursionDialog.setTitle(getString(R.string.alert));
		excursionDialog.setMessage(getString(R.string.loading_data));
		excursionDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		excursionDialog.setCanceledOnTouchOutside(false);

		getBranchsPD = new ProgressDialog(this);
		getBranchsPD.setTitle(getString(R.string.alert));
		getBranchsPD.setMessage(getString(R.string.onLoading));
		getBranchsPD.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		getBranchsPD.setCanceledOnTouchOutside(false);

		canShowErrorPD = new ProgressDialog(this);
		canShowErrorPD.setTitle(getString(R.string.alert));
		canShowErrorPD.setMessage(getString(R.string.onLoading));
		canShowErrorPD.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		canShowErrorPD.setCanceledOnTouchOutside(false);
	}

	private void initWheelInfo(final String[] bigClass,
			final String[][] smallClass, final HashMap<Integer, String> bigMap,
			final HashMap<Integer, HashMap<Integer, String>> smallMap,
			final int wheelConstant) {
		wheelView = LayoutInflater.from(LocationServiceActivity.this).inflate(
				R.layout.around_search_wheel, null);

		final WheelView bigClassView = (WheelView) wheelView
				.findViewById(R.id.bigClass);
		bigClassView.setVisibleItems(5);
		bigClassView.setAdapter(new ArrayWheelAdapter<String>(bigClass));

		final WheelView smallClassView = (WheelView) wheelView
				.findViewById(R.id.smallClass);
		smallClassView.setVisibleItems(5);

		switch (wheelConstant) {
		case AROUND_TYPE:
			bigClassView.addChangingListener(new OnWheelChangedListener() {

				@Override
				public void onChanged(WheelView wheel, int oldValue,
						int newValue) {
					smallClassView.setAdapter(new ArrayWheelAdapter<String>(
							smallClass[newValue]));
					smallClassView.setCurrentItem(aroundSmallItem);
				}
			});
			bigClassView.setCurrentItem(aroundBigItem);
			break;
		}

		// 确定
		Button sureBtn = (Button) wheelView.findViewById(R.id.sure);
		sureBtn.setOnClickListener(new View.OnClickListener() {
			String merchantUrl = ConfigManager.SERVER_URI
					+ ConfigManager.MAP_GET_MERCHANT_LIST;
			String urlBody = "";

			@Override
			public void onClick(View v) {
				final int bigItem = bigClassView.getCurrentItem();
				final int smallItem = smallClassView.getCurrentItem();
				if (bigMap.get(bigItem) != null) {
					type = bigMap.get(bigItem);
				} else {
					type = smallMap.get(bigItem).get(smallItem);
				}

				switch (wheelConstant) {
				case AROUND_TYPE:
					aroundBigItem = bigItem;
					aroundSmallItem = smallItem;

					// 若放大级别低于17, 则设置级别为17
					// controlZoomLevel();
					GeoPoint currentCenterPoint = mMapView.getMapCenter();
					currentLat = currentCenterPoint.getLatitudeE6() * 1.0f / 1e6;
					currentLon = currentCenterPoint.getLongitudeE6() * 1.0f / 1e6;
					Utils.printOutToConsole(currentLat + " " + currentLon);
					getBranchsWithType(type);
					
					break;
				}

				if (aroundPW.isShowing()) {
					aroundPW.dismiss();
				}
			}
		});

		// 取消
		Button cancelBtn = (Button) wheelView.findViewById(R.id.cancel);
		cancelBtn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (aroundPW.isShowing()) {
					aroundPW.dismiss();
				}
			}
		});
	}

	/**
	 * 定位
	 * 
	 * @param isAlsoQueryAround
	 *            是否查找周边
	 * @param isShowLocation
	 */
	private void initLatAndLon(final boolean isAlsoQueryAround,
			final boolean isShowLocation) {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				// 采用大众定位类定位
				locationService.getLocation(LocationServiceActivity.this,
						new Handler() {
							private String baidu;

							@Override
							public void handleMessage(Message msg) {
								switch (msg.what) {
								case 1001:
									if (locationDialog != null
											&& !locationDialog.isShowing())
										locationDialog.show();
									break;
								case 2001:
									locationDialog.dismiss();
									Bundle bundle = msg.getData();
									if (bundle != null) {
										currentLat = bundle.getDouble("lat");
										currentLon = bundle.getDouble("lon");
										excursionCurrLat = currentLat;
										excursionCurrLon = currentLon;
										baidu = bundle.getString("baiduLoc");
										if (null != baidu
												&& baidu.equals("baidu")) {
											showMyLocation(currentLat,
													currentLon, myMarker);
											GeoPoint myGeoPoint = new GeoPoint(
													(int) (excursionCurrLat * 1e6),
													(int) (excursionCurrLon * 1e6));
											mMapView.getController().setCenter(
													myGeoPoint);
											break;
										}
										// 偏移经纬度
										String excursionUrlBody = "from=2&to=4&x="
												+ String.valueOf(currentLon)
												+ "&y="
												+ String.valueOf(currentLat)
												+ "&mode=1";
										excursionConstant = LOCATION_EXCURSION;
										getExcursionValue(null,
												ConfigManager.MAP_BAIDU_URL
														+ excursionUrlBody,
												LOCATION_EXCURSION,
												isAlsoQueryAround,
												isShowLocation);
										GeoPoint myGeoPoint = new GeoPoint(
												(int) (excursionCurrLat * 1e6),
												(int) (excursionCurrLon * 1e6));
										Utils.printOutToConsole("lat:"
												+ excursionCurrLat
												+ "  ##  lon:"
												+ excursionCurrLon);
										mMapView.getController().setCenter(
												myGeoPoint);

									}
									break;
								case 3001:
									locationDialog.dismiss();
									if (msg.obj != null
											&& !isCancelLocationDialog) {

										currentLat = ConfigManager.default_current_lat;
										currentLon = ConfigManager.default_current_lon;

										// 偏移经纬度
										String excursionUrlBody = "from=2&to=4&x="
												+ String.valueOf(currentLon)
												+ "&y="
												+ String.valueOf(currentLat)
												+ "&mode=1";
										excursionConstant = LOCATION_EXCURSION;
										getExcursionValue(null,
												ConfigManager.MAP_BAIDU_URL
														+ excursionUrlBody,
												LOCATION_EXCURSION,
												isAlsoQueryAround,
												isShowLocation);
									}
									break;
								}
							}
						});
			}
		});
	}

	/**
	 * 显示我的位置
	 * 
	 * @param marker
	 */
	public void showMyLocation(double excursionCurrLat,
			double excursionCurrLon, Drawable marker) {
		Utils.printOutToConsole("lat:" + excursionCurrLat + "  @@  lon:"
				+ excursionCurrLon);
		GeoPoint myGeoPoint = new GeoPoint((int) (excursionCurrLat * 1e6),
				(int) (excursionCurrLon * 1e6));
		mMapView.getController().setCenter(myGeoPoint);

		OverlayItem item = new OverlayItem(myGeoPoint, "", "");
		List<OverlayItem> items = new ArrayList<OverlayItem>();
		items.add(item);

		MyLocationOverlayItem myOI = new MyLocationOverlayItem(
				LocationServiceActivity.this, marker, items);
		List<Overlay> overlays = mMapView.getOverlays();
		overlays.clear();
		overlays.add(myOI);
	}

	protected void moveToMyLocation() {
		GeoPoint myGeoPoint = new GeoPoint((int) (excursionCurrLat * 1e6),
				(int) (excursionCurrLon * 1e6));
		mMapView.getController().animateTo(myGeoPoint);
	}
	
	protected void moveToMyLocation(double cutLat,double cutLon){
		GeoPoint myGeoPoint = new GeoPoint((int) (cutLat * 1e6),
				(int) (cutLon * 1e6));
		mMapView.getController().animateTo(myGeoPoint);
	}

	Handler canShowErrorHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				if (canShowErrorPD != null && !canShowErrorPD.isShowing()) {
					canShowErrorPD.show();
				}
				break;
			case 2:
				canShowErrorPD.dismiss();
				break;
			case 3:
				canShowErrorPD.dismiss();
				if (msg.obj != null) {
					handleException(msg.obj.toString());
				}
				break;
			}
		};
	};

	Handler getBranchsHandler = new Handler() {
		@SuppressWarnings("unchecked")
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				if (getBranchsPD != null && !getBranchsPD.isShowing()) {
					getBranchsPD.show();
				}
				break;
			case 2:
				getBranchsPD.dismiss();
				// 木有查到数据时
				if (successState == NO_QUERY_RESULT) {
					// 清除所有标记, 当前位置不该取消
					showMyLocation(excursionCurrLat, excursionCurrLon, myMarker);

					showErrorCastDialog(getString(R.string.castError));
				}
				// 改变搜索类型时
				else if (successState == CHANGE_TYPE) {
					// 清除所有标记, 当前位置不该取消
					showMyLocation(excursionCurrLat, excursionCurrLon, myMarker);

					// 重置
					branchIndex = 0;
					branchCount = 0;
					requestUrlTime = 0;

					// 标点
					HashMap<Integer, BranchPoint> branchHM = (HashMap<Integer, BranchPoint>) msg.obj;
					addPoints(branchHM);
				}
				// 获取网点详情成功时
				else if (successState == GET_BRANCH_DETAIL_SUCCESS) {
					String currBranchCoord = (String) msg.obj;
					// Log.i("zhang.h", "网点待偏移经纬度：" + currBranchCoord);
					if (currBranchCoord != null && currBranchCoord.length() > 0) {
						String[] currBranchCoordArr = currBranchCoord
								.split(",");
						// 偏移当前坐标
						String excursionUrlBody = "from=2&to=4&x="
								+ currBranchCoordArr[0] + "&y="
								+ currBranchCoordArr[1] + "&mode=1";
						excursionConstant = ROUTE_EXCURSION;
						getExcursionValue(null, ConfigManager.MAP_BAIDU_URL
								+ excursionUrlBody, ROUTE_EXCURSION, false,
								true);
					}
				}
				break;
			case 3:
				getBranchsPD.dismiss();
				if (msg.obj != null) {
					handleException(msg.obj.toString());
				}
				break;
			}
		};
	};

	private void getBranchsWithType(final String type) {
		mid.waitDialog_.addFgTask(LocationServiceActivity.this, null, 0, 0, 0,
				new WaitDialog.Task(0) {
					// 网点集合
					HashMap<Integer, BranchPoint> branchHM = null;

					@Override
					public void run(WaitDialog dlg) throws Exception {
						// Message getBranchsM = new Message();
						// getBranchsM.what = 1;
						// getBranchsHandler.sendMessage(getBranchsM);

						String getBranchsUrl = ConfigManager.SERVER_URI
								+ ConfigManager.MAP_SEARCH_AROUND;
						StringBuffer urlBody = new StringBuffer();
						urlBody.append("lo=" + currentLon);
						urlBody.append("&la=" + currentLat);
						// 31.2380000,121.51670000
						// urlBody.append("lo=" + 121.51670000);
						// urlBody.append("&la=" + 31.2380000);
						if (type == null) {
							urlBody.append("&type=");
						} else {
							urlBody.append("&type=" + URLEncoder.encode(type));
						}
						branchHM = BankcommApplication.server
								.getBranchsJson(getBranchsUrl
										+ urlBody.toString());
					}

					@Override
					public void onSuccess(WaitDialog dlg) {
						super.onSuccess(dlg);

						Message getBranchsM = new Message();
						getBranchsM.what = 2;

						if (branchHM != null && branchHM.size() > 0) {
							getBranchsM.obj = branchHM;
							successState = CHANGE_TYPE;
						} else {
							successState = NO_QUERY_RESULT;
						}

						getBranchsHandler.sendMessage(getBranchsM);
					}

					@Override
					public void onFailure(WaitDialog dlg) {
						super.onFailure(dlg);
						Utils.printOutToConsole(getErrMsg());
						Message getBranchsM = new Message();
						getBranchsM.what = 3;
						getBranchsM.obj = errmsg_;
						getBranchsHandler.sendMessage(getBranchsM);
					}
				});
	}

	Handler branchExcursionHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1001:
				if (excursionDialog != null && !excursionDialog.isShowing()) {
					excursionDialog.show();
				}
				break;
			case 2001:
				excursionDialog.dismiss();
				if (msg.obj != null) {
					LPToastUtil.getInstance().getToast(
							"网点数：" + msg.obj.toString(),
							LocationServiceActivity.this);
				}
				moveToMyLocation(currentLat,currentLon);
				break;
			case 3001:
				excursionDialog.dismiss();
				break;
			}
		};
	};

	private void addPoints(final HashMap<Integer, BranchPoint> branchHM) {
		Message m = new Message();
		m.what = 1001;
		branchExcursionHandler.sendMessage(m);

		// 清空, POI图层集合、临时图层集合
		myGeoOverlayItem.mOverlays.clear();
		tempGeoOverlayItem.mOverlays.clear();

		for (int i = 0; i < mid.urlList.size(); i++) {
			excursionConstant = BRANCH_EXCURSION;
			getExcursionValue(branchHM, mid.urlList.get(i), BRANCH_EXCURSION,
					false, true);
		}
	}

	/**
	 * 显示无法查询到信息提示
	 */
	private void showErrorCastDialog(String info) {
		new AlertDialog.Builder(LocationServiceActivity.this).setTitle(
				R.string.alert).setMessage(info).setPositiveButton(
				R.string.quit, new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {

					}
				}).show();
	}

	private void showPopWin() {
		aroundPW = new PopupWindow(wheelView, width,
				WindowManager.LayoutParams.WRAP_CONTENT, true);
		aroundPW.setBackgroundDrawable(new BitmapDrawable()); // 是否点击窗口外的区域可取消
		aroundPW.setAnimationStyle(R.style.PopupAnimation);
		int yoff = DensityUtil.dip2px(LocationServiceActivity.this, 0);
		aroundPW.showAtLocation(rightLayout, Gravity.BOTTOM, 0, yoff);
		aroundPW.update();
	}

	// =================================================================驾车、公交、步行搜索
	// start
	private void routeInterface(int routeConstant) {
		Message m = new Message();
		m.what = 1001;
		branchExcursionHandler.sendMessage(m);

		// 将当前页面放置栈
		generateView();

		switch (routeConstant) {
		case 1:
			myDrivingSearch(excursionedBranchLat, excursionedBranchLon);
			break;
		case 2:
			myTransitSearch(excursionedBranchLat, excursionedBranchLon);
			break;
		case 3:
			myWalkingSearch(excursionedBranchLat, excursionedBranchLon);
			break;
		}
	}

	private void myDrivingSearch(double endLat, double endLon) {
		MKPlanNode start = new MKPlanNode();
		start.pt = new GeoPoint((int) (excursionCurrLat * 1e6),
				(int) (excursionCurrLon * 1e6));
		MKPlanNode end = new MKPlanNode();
		end.pt = new GeoPoint((int) (endLat * 1e6), (int) (endLon * 1e6));
		// 设置驾车路线搜索策略, 时间优先、 费用最少或距离最短
		mSearch.setDrivingPolicy(MKSearch.ECAR_TIME_FIRST);
		mSearch.drivingSearch(null, start, null, end);
	}

	private void myTransitSearch(double endLat, double endLon) {
		MKPlanNode start = new MKPlanNode();
		start.pt = new GeoPoint((int) (excursionCurrLat * 1e6),
				(int) (excursionCurrLon * 1e6));
		MKPlanNode end = new MKPlanNode();
		end.pt = new GeoPoint((int) (endLat * 1e6), (int) (endLon * 1e6));
		// 设置乘车路线搜索策略, 时间优先、最少换乘、 最少步行距离或不含地铁
		mSearch.setTransitPolicy(MKSearch.EBUS_TIME_FIRST);
		mSearch.transitSearch("上海", start, end); // 必须设置城市名
	}

	private void myWalkingSearch(double endLat, double endLon) {
		MKPlanNode start = new MKPlanNode();
		start.pt = new GeoPoint((int) (excursionCurrLat * 1e6),
				(int) (excursionCurrLon * 1e6));
		MKPlanNode end = new MKPlanNode();
		end.pt = new GeoPoint((int) (endLat * 1e6), (int) (endLon * 1e6));
		// 设置驾车路线搜索策略, 时间优先, 费用最少或距离最短
		mSearch.setDrivingPolicy(MKSearch.ECAR_TIME_FIRST);
		mSearch.walkingSearch(null, start, null, end);
	}

	// 搜索事件监听
	private MKSearchListener mkSearchListener = new MKSearchListener() {

		@Override
		public void onGetDrivingRouteResult(MKDrivingRouteResult res, int iError) {
			Message m = new Message();
			m.what = 2001;

			if (iError != 0 || res == null) {
				LPToastUtil.getInstance().getToast("抱歉，未找到结果",
						LocationServiceActivity.this);
				branchExcursionHandler.sendMessage(m);
				return;
			}

			RouteOverlay routeOverlay = new RouteOverlay(
					LocationServiceActivity.this, mMapView);
			routeOverlay.setData(res.getPlan(0).getRoute(0));
			mMapView.getOverlays().clear();
			mMapView.getOverlays().add(routeOverlay);
			mMapView.invalidate();
			mMapView.getController().animateTo(res.getStart().pt);

			branchExcursionHandler.sendMessage(m);
		}

		@Override
		public void onGetTransitRouteResult(MKTransitRouteResult res, int iError) {
			Message m = new Message();
			m.what = 2001;

			if (iError != 0 || res == null) {
				LPToastUtil.getInstance().getToast("抱歉，未找到结果",
						LocationServiceActivity.this);
				branchExcursionHandler.sendMessage(m);
				return;
			}
			TransitOverlay routeOverlay = new TransitOverlay(
					LocationServiceActivity.this, mMapView);
			// 此处仅展示一个方案作为示例
			routeOverlay.setData(res.getPlan(0));
			mMapView.getOverlays().clear();
			mMapView.getOverlays().add(routeOverlay);
			mMapView.invalidate();
			mMapView.getController().animateTo(res.getStart().pt);

			branchExcursionHandler.sendMessage(m);
		}

		@Override
		public void onGetWalkingRouteResult(MKWalkingRouteResult res, int iError) {
			Message m = new Message();
			m.what = 2001;

			if (iError != 0 || res == null) {
				LPToastUtil.getInstance().getToast("抱歉，未找到结果",
						LocationServiceActivity.this);
				branchExcursionHandler.sendMessage(m);
				return;
			}
			RouteOverlay routeOverlay = new RouteOverlay(
					LocationServiceActivity.this, mMapView);
			// 此处仅展示一个方案作为示例
			routeOverlay.setData(res.getPlan(0).getRoute(0));
			mMapView.getOverlays().clear();
			mMapView.getOverlays().add(routeOverlay);
			mMapView.invalidate();
			mMapView.getController().animateTo(res.getStart().pt);

			branchExcursionHandler.sendMessage(m);
		}

		@Override
		public void onGetAddrResult(MKAddrInfo res, int iError) {

		}

		@Override
		public void onGetPoiResult(MKPoiResult res, int type, int iError) {

		}

		@Override
		public void onGetBusDetailResult(MKBusLineResult arg0, int arg1) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onGetPoiDetailSearchResult(int arg0, int arg1) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onGetRGCShareUrlResult(String arg0, int arg1) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onGetSuggestionResult(MKSuggestionResult arg0, int arg1) {
			// TODO Auto-generated method stub

		}
	};

	private LinearLayout topRL;

	private Button changePosition;

	private LinearLayout line;

	// =================================================================驾车、公交、步行搜索
	// end

	@Override
	protected void onPause() {
		app.mBMapMan.stop();
		super.onPause();
	}

	@Override
	protected void onResume() {
		app.mBMapMan.start();
		super.onResume();
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

	private void gotoSearchAroundView() {
		rightLayout.removeAllViews();

		// 0. 清除栈内容
		clearPageStack();

		// 1. 改变栈键值
		stackKey = "searchAround";

		// 2. 显示界面
		RelativeLayout aroundSearchRL = new RelativeLayout(
				LocationServiceActivity.this);
		aroundSearchRL.setLayoutParams(new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.FILL_PARENT,
				RelativeLayout.LayoutParams.FILL_PARENT));

		// 如果使用地图SDK，请初始化地图Activity
		// LocationServiceActivity.this.initMapActivity(app.mBMapMan);

		ViewParent parent_ = mMapView.getParent();
		if (null != parent_) {
			((RelativeLayout) parent_).removeView(mMapView);
		}
		// 清除所有的Overlay
		mMapView.getOverlays().clear();
		aroundSearchRL.addView(mMapView);

		topRL = (LinearLayout) LayoutInflater
				.from(LocationServiceActivity.this).inflate(
						R.layout.sidebar_location_layout, null);
		RelativeLayout.LayoutParams topParm = new RelativeLayout.LayoutParams(
				Utils.getScaledValueX(100), Utils.getScaledValueY(160));
		topParm.addRule(RelativeLayout.CENTER_VERTICAL,
				RelativeLayout.ALIGN_LEFT);
		topRL.setLayoutParams(topParm);

		// 初始化滚轮信息
		wheelConstant = AROUND_TYPE;
		initWheelInfo(mid.bigClass, mid.smallClass, mid.bigMap, mid.smallMap,
				wheelConstant);

		// 定位图标
		locationIV = (ImageView) topRL.findViewById(R.id.btn_cur_location);
		locationIV.setOnClickListener(locationIVClickListener);
		// 周边搜索图标
		aroundIV = (ImageView) topRL.findViewById(R.id.btn_around_search);
		aroundIV.setOnClickListener(aroundIVClickListener);

		changePosition = (Button) topRL.findViewById(R.id.touch_back);
		changePosition.setOnClickListener(changePostionListener);
		line = (LinearLayout) topRL.findViewById(R.id.locaton_btn_content);
		line.setVisibility(View.GONE);
		changePosition.setBackgroundResource(R.drawable.button_bianlan1);
		show = false;
		aroundSearchRL.addView(topRL);
		rightLayout.addView(aroundSearchRL);

		// 加入当前位置
		initLatAndLon(false, true);

		// 3. 加入栈(bmapRL固定，保证返回至第一个页面正确，该处bmapRL只是个标识而已，地图界面特殊处理)
		pushPageToStack(bmapRL, stackKey);
	}

	private boolean isFirstIn;

	private void gotoNodeSearch() {
		// 0. 清除栈内容
		clearPageStack();

		// 1. 改变栈键值
		stackKey = "nodeSearch";

		mid.waitDialog_.addFgTask(LocationServiceActivity.this, null, 0, 0, 0,
				new WaitDialog.Task(0) {
					Map<String, NodeSearch> nodeSearchMap;

					@Override
					public void run(WaitDialog dlg) throws Exception {
						// Message msg = new Message();
						// msg.what = 1;
						// canShowErrorHandler.sendMessage(msg);

						String nodeSearchUrl = ConfigManager.SERVER_URI
								+ ConfigManager.MAP_GET_NODE_SEARCH;
						nodeSearchMap = BankcommApplication.server
								.getNodeSearchData(nodeSearchUrl);
					};

					public void onSuccess(WaitDialog dlg) {
						Message msg = new Message();
						msg.what = 2;

						// 2. 显示界面
						LocationServiceActivity.this
								.runOnUiThread(new Runnable() {

									@Override
									public void run() {
										final View nodeSearchMainView = getLayoutInflater()
												.inflate(
														R.layout.node_search_main,
														null);

										// 查看周边网点
										Button queryAroundBtn = (Button) nodeSearchMainView
												.findViewById(R.id.queryAround);
										queryAroundBtn
												.setOnClickListener(new View.OnClickListener() {

													@Override
													public void onClick(View v) {
														isFirstIn = true;
														hideSoftInput();

														final RelativeLayout aroundSearchRL = new RelativeLayout(
																LocationServiceActivity.this);
														aroundSearchRL
																.setLayoutParams(new RelativeLayout.LayoutParams(
																		RelativeLayout.LayoutParams.FILL_PARENT,
																		RelativeLayout.LayoutParams.FILL_PARENT));

														// 如果使用地图SDK，请初始化地图Activity
														LocationServiceActivity.this
																.initMapActivity(app.mBMapMan);

														ViewParent parent_ = mMapView
																.getParent();
														if (null != parent_) {
															((RelativeLayout) parent_)
																	.removeView(mMapView);
														}
														// 清除所有的Overlay
														mMapView.getOverlays()
																.clear();
														aroundSearchRL
																.addView(mMapView);

														topRL = (LinearLayout) LayoutInflater
																.from(
																		LocationServiceActivity.this)
																.inflate(
																		R.layout.sidebar_location_layout,
																		null);
														RelativeLayout.LayoutParams topParm = new RelativeLayout.LayoutParams(
																Utils
																		.getScaledValueX(100),
																Utils
																		.getScaledValueY(160));
														topParm
																.addRule(
																		RelativeLayout.CENTER_VERTICAL,
																		RelativeLayout.ALIGN_LEFT);
														topRL
																.setLayoutParams(topParm);

														// 初始化滚轮信息
														wheelConstant = AROUND_TYPE;
														initWheelInfo(
																mid.bigClass,
																mid.smallClass,
																mid.bigMap,
																mid.smallMap,
																wheelConstant);
														line = (LinearLayout) topRL
																.findViewById(R.id.locaton_btn_content);
														line
																.setVisibility(View.GONE);
														show = false;
														ImageView locationIV = (ImageView) topRL
																.findViewById(R.id.btn_cur_location);
														locationIV
																.setOnClickListener(locationIVClickListener);
														ImageView aroundIV = (ImageView) topRL
																.findViewById(R.id.btn_around_search);
														aroundIV
																.setOnClickListener(aroundIVClickListener);
														changePosition = (Button) topRL
																.findViewById

																(R.id.touch_back);

														changePosition
																.setOnClickListener

																(changePostionListener);
														aroundSearchRL
																.addView(topRL);

														LocationServiceActivity.this
																.runOnUiThread(new Runnable() {
																	@Override
																	public void run() {
																		// 1.移除右侧View
																		rightLayout
																				.removeAllViews();

																		rightLayout
																				.addView(aroundSearchRL);
																	}
																});

														initLatAndLon(true,
																true);

														// 把当前页面放至栈
														pushPageToStack(bmapRL,
																stackKey);
													}
												});

										// 城市
										final MyCityChoose myCityChoose = (MyCityChoose) nodeSearchMainView
												.findViewById(R.id.cityChoose);
										myCityChoose.init(
												LocationServiceActivity.this,
												nodeSearchMap.get("citys")
														.getData());

										// 类型
										LinkedHashMap<String, String> typeMap = new LinkedHashMap<String, String>();
										try {
											JSONArray typeJA = new JSONArray(
													nodeSearchMap.get("types")
															.getData());
											for (int i = 0; i < typeJA.length(); i++) {
												JSONObject typeJO = (JSONObject) typeJA
														.get(i);
												typeMap
														.put(
																typeJO
																		.getString("name"),
																typeJO
																		.getString("value"));
											}
										} catch (JSONException e) {
											e.printStackTrace();
										}
										mySelect = (MySelect) nodeSearchMainView
												.findViewById(R.id.typeChoose);
										mySelect.initWeelSelect(typeMap);

										// 关键字
										final EditText keywordET = (EditText) nodeSearchMainView
												.findViewById(R.id.keywordET);

										// 查询
										Button nodeQueryBtn = (Button) nodeSearchMainView
												.findViewById(R.id.nodeQuery);
										nodeQueryBtn
												.setOnClickListener(new View.OnClickListener() {

													@Override
													public void onClick(View v) {
														hideSoftInput();

														final String keyword = keywordET
																.getText()
																.toString();

														// 进入网点列表
														if (keyword != null
																&& !""
																		.equals(keyword)) {

															mid.waitDialog_
																	.addFgTask(
																			LocationServiceActivity.this,
																			null,
																			0,
																			0,
																			0,
																			new WaitDialog.Task(
																					0) {
																				NodeListInfo nodeListInfo;

																				@Override
																				public void run(
																						WaitDialog dlg)
																						throws Exception {
																					// Message
																					// msg
																					// =
																					// new
																					// Message();
																					// msg.what
																					// =
																					// 1;
																					// canShowErrorHandler
																					// .sendMessage(msg);

																					// 拼装请求参数
																					String merchantUrl = ConfigManager.SERVER_URI
																							+ ConfigManager.MAP_GET_NODE;
																					nodeSearchUrlBody = nodeSearchMap
																							.get(
																									"citys")
																							.getParamName()
																							+ "="
																							+ Utils
																									.escapeURIComponent(myCityChoose
																											.getValue())
																							+ "&q="
																							+ Utils
																									.escapeURIComponent(keyword)
																							+ "&"
																							+ nodeSearchMap
																									.get(
																											"types")
																									.getParamName()
																							+ "="
																							+ Utils
																									.escapeURIComponent(mySelect
																											.getValue())
																							+ "&p=1";
																					nodeListInfo = BankcommApplication.server
																							.getNodes(merchantUrl
																									+ nodeSearchUrlBody);
																				};

																				public void onSuccess(
																						WaitDialog dlg) {
																					Message msg = new Message();
																					msg.what = 2;
																					runOnUiThread(new Runnable() {
																						public void run() {

																							// 2.
																							// 显示界面
																							final View nodeSearchListView = getLayoutInflater()
																									.inflate(
																											R.layout.node_search_list,
																											null);

																							// 结果文本
																							TextView resTV = (TextView) nodeSearchListView
																									.findViewById(R.id.resTV);
																							resTV
																									.setText(nodeListInfo
																											.getMsg());

																							// 无结果文本
																							TextView nodeListNoResTV = (TextView) nodeSearchListView
																									.findViewById(R.id.noResText);

																							// 列表
																							nodeSearchLV = (MyIXListView) nodeSearchListView
																									.findViewById(R.id.nodeSearchLV);
																							nodeSearchLV
																									.setOnItemClickListener(new AdapterView.OnItemClickListener() {

																										@Override
																										public void onItemClick(
																												AdapterView<?> parent,
																												View view,
																												int position,
																												long id) {
																											final NodeInfo nodeInfo = (NodeInfo) parent
																													.getAdapter()
																													.getItem(
																															position);

																											mid.waitDialog_
																													.addFgTask(
																															LocationServiceActivity.this,
																															null,
																															0,
																															0,
																															0,
																															new WaitDialog.Task(
																																	0) {
																																String nodeDetailResult = null;

																																@Override
																																public void run(
																																		WaitDialog dlg)
																																		throws Exception {
																																	// Message
																																	// getNodeDetailMsg
																																	// =
																																	// new
																																	// Message();
																																	// getNodeDetailMsg.what
																																	// =
																																	// 1;
																																	// getBranchsHandler
																																	// .sendMessage(getNodeDetailMsg);

																																	String merchantDetailUrl = ConfigManager.SERVER_URI
																																			+ ConfigManager.MAP_GET_NODE_DETAIL
																																			+ "markCode="
																																			+ nodeInfo
																																					.getMarkCode();
																																	nodeDetailResult = (String) LPMid
																																			.getInstance().hm_
																																			.sendPostRequest(
																																					merchantDetailUrl,
																																					null,
																																					this,
																																					null,
																																					null);
																																}

																																@Override
																																public void onSuccess(
																																		WaitDialog dlg) {
																																	Message getNodeDetailMsg = new Message();
																																	getNodeDetailMsg.what = 2;

																																	String branchCoord = null;
																																	branchCoord = getNodeDetailInfo(
																																			nodeDetailResult,
																																			branchCoord);
																																	getNodeDetailMsg.obj = branchCoord;
																																	successState = GET_BRANCH_DETAIL_SUCCESS;
																																	getBranchsHandler
																																			.sendMessage(getNodeDetailMsg);

																																	super
																																			.onSuccess(dlg);
																																}

																																@Override
																																public void onFailure(
																																		WaitDialog dlg) {
																																	Utils
																																			.printOutToConsole(getErrMsg());
																																	Message getNodeDetailMsg = new Message();
																																	getNodeDetailMsg.what = 3;
																																	getNodeDetailMsg.obj = errmsg_;
																																	getBranchsHandler
																																			.sendMessage(getNodeDetailMsg);

																																	super
																																			.onFailure(dlg);
																																}
																															});
																										}
																									});

																							if (nodeListInfo
																									.getNodeInfos() != null
																									&& nodeListInfo
																											.getNodeInfos()
																											.size() > 0) {
																								nodeSearchLV
																										.setVisibility(View.VISIBLE);
																								nodeListNoResTV
																										.setVisibility(View.GONE);

																								// 设置下拉刷新是否可用
																								nodeSearchLV
																										.setPullRefreshEnable(false);
																								// 设置上拉加载更多是否可用
																								if ("0"
																										.equals(nodeListInfo
																												.getCurrPage())) {
																									nodeSearchLV
																											.setPullLoadEnable(false);
																								} else {
																									nodeSearchLV
																											.setPullLoadEnable(true);
																								}

																								nodeInfoAdapter = new NodeInfoAdapter(
																										LocationServiceActivity.this);
																								nodeInfoAdapter
																										.setList(nodeListInfo
																												.getNodeInfos());
																								nodeSearchLV
																										.setAdapter(nodeInfoAdapter);
																								nodeSearchLV
																										.setXListViewListener(LocationServiceActivity.this);
																							} else {
																								nodeSearchLV
																										.setVisibility(View.GONE);
																								nodeListNoResTV
																										.setVisibility(View.VISIBLE);
																							}

																							// LocationServiceActivity.this.runOnUiThread(new
																							// Runnable()
																							// {
																							// @Override
																							// public
																							// void
																							// run()
																							// {
																							// 1.移除右侧View
																							rightLayout
																									.removeAllViews();

																							rightLayout
																									.addView(nodeSearchListView);
																							// }
																							// });

																							// 把当前页面放至栈
																							pushPageToStack(
																									nodeSearchListView,
																									stackKey);
																						}
																					});

																					canShowErrorHandler
																							.sendMessage(msg);
																					super
																							.onSuccess(dlg);
																				};

																				public void onFailure(
																						WaitDialog dlg) {
																					Utils
																							.printOutToConsole(getErrMsg());
																					Message msg = new Message();
																					msg.what = 3;
																					msg.obj = errmsg_;
																					canShowErrorHandler
																							.sendMessage(msg);

																					super
																							.onFailure(dlg);
																				};
																			});
														}
														// 若关键字为空, 提示
														else {
															showErrorCastDialog(getString(R.string.keywordError));
														}
													}
												});

										LocationServiceActivity.this
												.runOnUiThread(new Runnable() {
													@Override
													public void run() {
														// 1.移除右侧View
														rightLayout
																.removeAllViews();

														rightLayout
																.addView(nodeSearchMainView);
													}
												});

										// 3. 加入栈
										pushPageToStack(nodeSearchMainView,
												stackKey);
									}
								});

						canShowErrorHandler.sendMessage(msg);
						super.onSuccess(dlg);
					};

					public void onFailure(WaitDialog dlg) {
						Utils.printOutToConsole(getErrMsg());
						Message msg = new Message();
						msg.what = 3;
						msg.obj = errmsg_;
						canShowErrorHandler.sendMessage(msg);

						super.onFailure(dlg);
					};
				});
	}

	/**
	 * <pre>
	 * 把当前View放至栈
	 * currView 当前View
	 * channelName 频道名称
	 * </pre>
	 */
	private void pushPageToStack(View currView, String channelName) {
		PageInfo newPage = new PageInfo();
		List<View> views = new ArrayList<View>();
		views.add(currView);
		newPage.setComponents(views);
		newPage.setLeftSideVisible(true);
		newPage.setRightSideVisible(true);
		newPage.setBackInfo(null);
		pageInfos.get(channelName).push(newPage);
	}

	/**
	 * 清除栈内容
	 */
	private void clearPageStack() {
		pageInfos.get("searchAround").clear();
		pageInfos.get("specialShop").clear();
		pageInfos.get("nodeSearch").clear();
	}

	/**
	 * 监听返回键
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			keybackPressed();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	public void keybackPressed() {
		LPMid.hideInputMethod(this);
		Stack<PageInfo> currStack = pageInfos.get(stackKey);
		if (currStack == null || currStack.size() <= 1) {
			// if (GoogleGetLocation != null) {
			// GoogleGetLocation.gpsOrNetWorkTimer.cancel();
			// BaiduRequestLocation baiduGetLoc =
			// GoogleGetLocation.baiduGetLocation;
			// if (baiduGetLoc != null) {
			// baiduGetLoc.timer.cancel();
			// }
			// }
			exitApp();
		} else {
			// 取出上次的报文, 重新加载
			backRefresh(currStack);
		}
	}

	/**
	 * 退出应用
	 */
	private void exitApp() {
		finish();
	}

	/**
	 * <pre>
	 * 返回到上一个页面
	 * currStack 当前栈
	 * </pre>
	 */
	public void backRefresh(final Stack<PageInfo> currStack) {
		if (currStack != null && currStack.size() > 1) {
			LPMid.getInstance().waitDialog_.addFgTask(
					LocationServiceActivity.this, null, 0, 0, 0,
					new WaitDialog.Task(0) {
						// 返回的报文数据串
						PageInfo lastPage = null;

						@Override
						public void run(WaitDialog dlg) throws Exception {
							// Message msg = new Message();
							// msg.what = 1;
							// canShowErrorHandler.sendMessage(msg);

							currStack.pop();
							if (currStack.size() < 1) {
								lastPage = null;
							} else {
								lastPage = (PageInfo) currStack.peek();
							}
						}

						@Override
						public void onSuccess(WaitDialog dlg) {
							Message msg = new Message();
							msg.what = 2;

							if (lastPage == null) {
								exitApp();
							} else {
								// 放至主线程
								LocationServiceActivity.this
										.runOnUiThread(new Runnable() {
											@Override
											public void run() {
												try {
													rightLayout
															.removeAllViews();
													for (View singView : lastPage
															.getComponents()) {
														if (singView == bmapRL) {
															RelativeLayout aroundSearchRL = new RelativeLayout(
																	LocationServiceActivity.this);
															aroundSearchRL
																	.setLayoutParams(new RelativeLayout.LayoutParams(
																			RelativeLayout.LayoutParams.FILL_PARENT,
																			RelativeLayout.LayoutParams.FILL_PARENT));

															// 如果使用地图SDK，请初始化地图Activity
															LocationServiceActivity.this
																	.initMapActivity(app.mBMapMan);

															ViewParent parent_ = mMapView
																	.getParent();
															if (null != parent_) {
																((RelativeLayout) parent_)
																		.removeView(mMapView);
															}
															// 清除所有的Overlay
															mMapView
																	.getOverlays()
																	.clear();
															aroundSearchRL
																	.addView(mMapView);

															// 加入当前位置
															showMyLocation(
																	excursionCurrLat,
																	excursionCurrLon,
																	myMarker);

															// 加入网点
															if (tempGeoOverlayItem != null) {
																mMapView
																		.getOverlays()
																		.add(
																				tempGeoOverlayItem);
																mMapView
																		.invalidate();
															}

															topRL = (LinearLayout) LayoutInflater
																	.from(
																			LocationServiceActivity.this)
																	.inflate(
																			R.layout.sidebar_location_layout,
																			null);
															RelativeLayout.LayoutParams topParm = new RelativeLayout.LayoutParams(
																	Utils
																			.getScaledValueX(100),
																	Utils
																			.getScaledValueY(160));
															topParm
																	.addRule(
																			RelativeLayout.CENTER_VERTICAL,
																			RelativeLayout.ALIGN_LEFT);
															topRL
																	.setLayoutParams(topParm);
															line = (LinearLayout) topRL
																	.findViewById(R.id.locaton_btn_content);
															line
																	.setVisibility(View.GONE);
															show = false;
															ImageView locationIV = (ImageView) topRL
																	.findViewById(R.id.btn_cur_location);
															locationIV
																	.setOnClickListener(locationIVClickListener);
															ImageView aroundIV = (ImageView) topRL
																	.findViewById(R.id.btn_around_search);
															aroundIV
																	.setOnClickListener(aroundIVClickListener);

															changePosition = (Button) topRL
																	.findViewById

																	(R.id.touch_back);

															changePosition
																	.setOnClickListener

																	(changePostionListener);

															aroundSearchRL
																	.addView(topRL);

															rightLayout
																	.addView(aroundSearchRL);
														} else {
															rightLayout
																	.addView(singView);
														}
													}
												} catch (Exception e) {
													e.printStackTrace();
												}
											}
										});
							}

							canShowErrorHandler.sendMessage(msg);
							super.onSuccess(dlg);
						}

						@Override
						public void onFailure(WaitDialog dlg) {
							Utils.printOutToConsole(getErrMsg());
							Message msg = new Message();
							msg.what = 3;
							msg.obj = errmsg_;
							canShowErrorHandler.sendMessage(msg);

							super.onFailure(dlg);
						}
					});
		}
	}

	int branchIndex = 0;
	int requestUrlTime = 0;
	int branchCount = 0;

	/**
	 * 偏移方法
	 * 
	 * @param branchHM
	 * @param url
	 * @param locationExcursion
	 * @param isAlsoQueryAround
	 *            是否查询周边
	 * @param isShowLocation
	 *            是否显示当前位置
	 */
	private void getExcursionValue(
			final HashMap<Integer, BranchPoint> branchHM, String url,
			final int locationExcursion, final boolean isAlsoQueryAround,
			final boolean isShowLocation) {
		Handler handler = new Handler() {
			public void handleMessage(Message message) {
				switch (message.what) {
				case HttpConnection.DID_START:
					if (excursionConstant == LOCATION_EXCURSION) {
						if (excursionDialog != null
								&& !excursionDialog.isShowing()) {
							excursionDialog.show();
						}
					}
					break;
				case HttpConnection.DID_SUCCEED:
					String response = (String) message.obj;
					try {
						// 偏移当前位置
						if (excursionConstant == LOCATION_EXCURSION) {
							JSONArray retResJA = new JSONArray(response);
							JSONObject retResJO = (JSONObject) retResJA.get(0);
							String excursionLon = new String(Base64
									.decode(retResJO.getString("x")));
							String excursionLat = new String(Base64
									.decode(retResJO.getString("y")));
							excursionCurrLon = Double.valueOf(excursionLon);
							excursionCurrLat = Double.valueOf(excursionLat);
							if (isShowLocation) {
								showMyLocation(excursionCurrLat,
										excursionCurrLon, myMarker);
							}
							// 显示各种路线
							else {
								routeInterface(routeConstant);
							}

							// 关闭对话框
							excursionDialog.dismiss();

							// 查找周边
							if (isAlsoQueryAround) {
								// Log.i("zhang.h", "准备查找周边...");

								// 若放大级别低于17, 则设置级别为17
								// controlZoomLevel();
								// 类型
								if (mySelect != null) {
									getBranchsWithType(mySelect.getValue());
								}
							}
						}
						// 偏移搜索到的网点
						else if (excursionConstant == BRANCH_EXCURSION) {
							JSONArray retResJA = new JSONArray(response);
							branchCount += retResJA.length();
							for (int i = 0; i < retResJA.length(); i++) {
								BranchPoint currBranch = branchHM
										.get(branchIndex);
								if (currBranch != null) {
									JSONObject retResJO = (JSONObject) retResJA
											.get(i);
									currBranch.setLonPoint(new String(Base64
											.decode(retResJO.getString("x"))));
									currBranch.setLatPoint(new String(Base64
											.decode(retResJO.getString("y"))));

									GeoPoint currentPoint = new GeoPoint(
											(int) (Double.valueOf(currBranch
													.getLatPoint()) * 1e6),
											(int) (Double.valueOf(currBranch
													.getLonPoint()) * 1e6));
									if (currAct.equals("search_around")) {
										mMapView.getController().setCenter(
												currentPoint);
									} else {
										if (!isFirstIn) {
											mMapView.getController().setCenter(
													currentPoint);
											mMapView.getController()
													.setZoom(14);
										}
									}
									OverlayItem item = new OverlayItem(
											currentPoint, currBranch.getName(),
											currBranch.getAddress()
													+ "|"
													+ currBranch
															.getBranchBody());
									myGeoOverlayItem.addOverlay(item);
									tempGeoOverlayItem.addOverlay(item);

									branchIndex++;
								}
							}
							if (isFirstIn) {
								isFirstIn = false;
							}

							// 统计请求次数
							requestUrlTime++;
							if (requestUrlTime == mid.urlList.size()
									&& myGeoOverlayItem != null) {
								Message msg = new Message();
								msg.what = 2001;
								msg.obj = branchCount;

								mMapView.getOverlays().add(myGeoOverlayItem);
								mMapView.invalidate();

								branchExcursionHandler.sendMessage(msg);
							}
						}
						// 路径点偏移
						else if (excursionConstant == ROUTE_EXCURSION) {
							JSONArray retResJA = new JSONArray(response);
							JSONObject retResJO = (JSONObject) retResJA.get(0);
							String excursionLon = new String(Base64
									.decode(retResJO.getString("x")));
							String excursionLat = new String(Base64
									.decode(retResJO.getString("y")));
							excursionedBranchLon = Double.valueOf(excursionLon);
							excursionedBranchLat = Double.valueOf(excursionLat);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					break;
				case HttpConnection.DID_ERROR:
					Exception e = (Exception) message.obj;
					e.printStackTrace();
					break;
				}
			}
		};
		new HttpConnection(handler).get(url);
	}

	/**
	 * 控制缩放级别
	 */
	private void controlZoomLevel() {
		// int currZoomLevel = mMapView.getZoomLevel();
		// if (currZoomLevel < 17) {
		// mMapView.getController().setZoom(17);
		// GeoPoint myGeoPoint = new GeoPoint((int) (excursionCurrLat * 1e6),
		// (int) (excursionCurrLon * 1e6));
		// mMapView.getController().setCenter(myGeoPoint);
		// }
	}

	// 上拉加载更多回调方法
	@Override
	public void onLoadMore() {
		ixHandler.postDelayed(new Runnable() {
			@Override
			public void run() {
				mid.waitDialog_.addBgTask(new Task(0) {

					NodeListInfo nodeListInfo;

					@Override
					public void run(WaitDialog dlg) throws Exception {

						if ("nodeSearch".equals(stackKey)) {
							// 拼装请求参数
							String currPage = mid.pm_.autoTextDB_
									.get("nodeSearchCurrPage");
							String merchantUrl = ConfigManager.SERVER_URI
									+ ConfigManager.MAP_GET_NODE;
							String requestUrl = merchantUrl + nodeSearchUrlBody
									+ "&currPage=" + currPage;
							nodeListInfo = BankcommApplication.server
									.getNodes(requestUrl);
						}
					}

					@Override
					public void onFailure(WaitDialog dlg) {
						super.onFailure(dlg);
						handleException(getErrMsg());
					}

					@Override
					public void onSuccess(WaitDialog dlg) {
                        LocationServiceActivity.this.runOnUiThread(new Runnable() {
							
							@Override
							public void run() {
								// 若当前页为0, 则不显示"更多"
								if ("0".equals(nodeListInfo.getCurrPage())) {
									nodeSearchLV.setPullLoadEnable(false);
								}
								
								ArrayList<NodeInfo> lists = nodeInfoAdapter.getList();
								lists.addAll(nodeListInfo.getNodeInfos());
								
								nodeInfoAdapter.setList(lists);
								nodeInfoAdapter.notifyDataSetChanged();
								onLoad(nodeSearchLV);
								
							}
						});
						super.onSuccess(dlg);
					}
				});

			}
		}, 2000);
	}

	// 下拉刷新回调方法
	@Override
	public void onRefresh() {

	}

	private void onLoad(MyIXListView ixListView) {
		ixListView.stopRefresh();
		ixListView.stopLoadMore();
		ixListView.setRefreshTime("刚刚");
	}

	// 隐藏键盘
	private void hideSoftInput() {
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		if (imm.isActive()
				&& LocationServiceActivity.this.getCurrentFocus() != null) {
			imm.hideSoftInputFromWindow(LocationServiceActivity.this
					.getCurrentFocus().getWindowToken(),
					InputMethodManager.HIDE_NOT_ALWAYS);
		}
	}

	boolean show = true;
	OnClickListener changePostionListener = new OnClickListener() {

		@Override
		public void onClick(View arg0) {

			Animation anim = AnimationUtils.loadAnimation(
					LocationServiceActivity.this, R.anim.sidebar_dismiss);
			anim.setAnimationListener(new AnimationListener() {

				@Override
				public void onAnimationStart(Animation arg0) {
				}

				@Override
				public void onAnimationRepeat(Animation arg0) {

				}

				@Override
				public void onAnimationEnd(Animation arg0) {
					changePosition
							.setBackgroundResource(R.drawable.button_bianlan1);
					line.setVisibility(View.GONE);
				}
			});
			Animation animShow = AnimationUtils.loadAnimation(
					LocationServiceActivity.this, R.anim.sidebar_show);
			animShow.setAnimationListener(new AnimationListener() {

				@Override
				public void onAnimationStart(Animation arg0) {
					line.setVisibility(View.VISIBLE);
					changePosition
							.setBackgroundResource(R.drawable.button_bianlan);
				}

				@Override
				public void onAnimationRepeat(Animation arg0) {
				}

				@Override
				public void onAnimationEnd(Animation arg0) {

				}
			});

			if (show) {
				topRL.startAnimation(anim);
				show = false;
			} else {
				topRL.startAnimation(animShow);
				show = true;
			}
		}

	};

	private String getMerchantDetailInfo(String merchantDetailResult,
			String branchCoord) {
		try {
			String[] favorableInfoArr = null;
			String[] favorableEndTimeArr = null;

			JSONObject branchResultJO = new JSONObject(merchantDetailResult);

			JSONArray aroundShopImageUrls = branchResultJO
					.getJSONArray("aroundShopImageUrls");

			String[] aroundShopUrl = new String[aroundShopImageUrls.length()];
			final ArrayList<String> list = new ArrayList<String>();
			for (int i = 0; i < aroundShopImageUrls.length(); i++) {
				JSONObject urlObj = aroundShopImageUrls.getJSONObject(i);
				aroundShopUrl[i] = urlObj.getString("aroundShopImageUrl");
				list.add(aroundShopUrl[i]);
			}

			String merchantTitle = branchResultJO.getString("merchantTitle");
			String merchantAddress = branchResultJO
					.getString("merchantAddress");
			String merchantPhone = branchResultJO.getString("merchantPhone");
			branchCoord = branchResultJO.getString("merchantCoord");

			// 优惠信息(可能会有多条)
			JSONArray infoJA = new JSONArray(branchResultJO.getString("info"));
			if (infoJA.length() > 0) {
				for (int i = 0; i < infoJA.length(); i++) {
					favorableInfoArr = new String[infoJA.length()];
					favorableEndTimeArr = new String[infoJA.length()];

					JSONObject currentInfoJO = (JSONObject) infoJA.get(i);
					favorableInfoArr[i] = currentInfoJO
							.getString("favorableInfo");
					favorableEndTimeArr[i] = currentInfoJO
							.getString("favorableEndTime");
				}
			}

			String merchantIntroduce = branchResultJO
					.getString("merchantIntroduce");
			String merchantSpecial = branchResultJO
					.getString("merchantSpecial");
			String merchantRegion = branchResultJO.getString("merchantRegion");
			String merchantTraffic = branchResultJO
					.getString("merchantTraffic");
			String merchantParking = branchResultJO
					.getString("merchantParking");

			final View branchDetail = getLayoutInflater().inflate(
					R.layout.merchant_detail, null);

			// LOGO
			merchantLogoImage = (MostPopShopGallery) branchDetail
					.findViewById(R.id.merchantLogoImage);

			LocationServiceActivity.this.runOnUiThread(new Runnable() {

				@Override
				public void run() {
					merchantLogoImage.initLayout(LocationServiceActivity.this,
							list);
				}
			});

			// 名称
			TextView merchantTitleText = (TextView) branchDetail
					.findViewById(R.id.merchantTitleText);
			merchantTitleText.setText(merchantTitle);

			// 地址
			TextView merchantAddressText = (TextView) branchDetail
					.findViewById(R.id.merchantAddressText);
			merchantAddressText.setText(getString(R.string.merchant_address)
					+ merchantAddress);
			ImageView merchantAddressImage = (ImageView) branchDetail
					.findViewById(R.id.merchantAddressImage);
			merchantAddressImage.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if (excursionedBranchLon == 0.0) {
						showErrorCastDialog(LocationServiceActivity.this
								.getString(R.string.locationError));
					} else {
						generateView();
						showMyLocation(excursionedBranchLat,
								excursionedBranchLon, poiMarker);
					}
				}
			});

			// 驾车路线
			ImageView drivingImage = (ImageView) branchDetail
					.findViewById(R.id.drivingImage);
			drivingImage.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// 判断经纬度是否存在
					if (excursionedBranchLon == 0.0) {
						showErrorCastDialog(LocationServiceActivity.this
								.getString(R.string.drivingError));
					} else {
						routeConstant = DRIVING;
						// 未定位过
						if (excursionCurrLon == 0D) {
							initLatAndLon(false, false);
						}
						// 定位过
						else {
							routeInterface(routeConstant);
						}
					}
				}
			});

			// 公交路线
			ImageView busImage = (ImageView) branchDetail
					.findViewById(R.id.busImage);
			busImage.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					if (excursionedBranchLon == 0.0) {
						showErrorCastDialog(LocationServiceActivity.this
								.getString(R.string.transitError));
					} else {
						routeConstant = TRANSIT;
						// 未定位过
						if (excursionCurrLon == 0D) {
							initLatAndLon(false, false);
						}
						// 定位过
						else {
							routeInterface(routeConstant);
						}
					}
				}
			});

			// 步行路线
			ImageView walkingImage = (ImageView) branchDetail
					.findViewById(R.id.walkingImage);
			walkingImage.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					if (excursionedBranchLon == 0.0) {
						showErrorCastDialog(LocationServiceActivity.this
								.getString(R.string.walkingError));
					} else {
						routeConstant = WALKING;
						// 未定位过
						if (excursionCurrLon == 0D) {
							initLatAndLon(false, false);
						}
						// 定位过
						else {
							routeInterface(routeConstant);
						}
					}
				}
			});

			// 电话
			TextView merchantPhoneText = (TextView) branchDetail
					.findViewById(R.id.merchantPhoneText);
			merchantPhoneText.setText(getString(R.string.merchant_phone)
					+ merchantPhone);

			// 优惠信息
			if (favorableInfoArr != null) {
				LinearLayout favorableInfosLayout = (LinearLayout) branchDetail
						.findViewById(R.id.favorableInfos);

				for (int i = 0; i < favorableInfoArr.length; i++) {
					String favorableInfo = favorableInfoArr[i];
					String favorableEndTime = favorableEndTimeArr[i];

					LinearLayout layout = new LinearLayout(
							LocationServiceActivity.this);
					LayoutParams layoutParams = new LayoutParams(
							LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
					layoutParams.leftMargin = 10;
					layoutParams.rightMargin = 10;
					layoutParams.bottomMargin = 10;
					layout.setLayoutParams(layoutParams);
					layout.setOrientation(LinearLayout.VERTICAL);

					TextView infoText = new TextView(
							LocationServiceActivity.this);
					LayoutParams infoLayoutParam = new LayoutParams(
							LayoutParams.WRAP_CONTENT,
							LayoutParams.WRAP_CONTENT);
					infoLayoutParam.bottomMargin = 7;
					infoText.setLayoutParams(infoLayoutParam);
					infoText.setText(favorableInfo);
					infoText.setTextColor(Color.rgb(127, 157, 227));
					layout.addView(infoText);

					View view = new View(LocationServiceActivity.this);
					view
							.setBackgroundResource(R.drawable.horizontal_separation_line);
					view.setLayoutParams(new LayoutParams(
							LayoutParams.FILL_PARENT, 1));
					layout.addView(view);

					TextView timeText = new TextView(
							LocationServiceActivity.this);
					LayoutParams timeLayoutParam = new LayoutParams(
							LayoutParams.WRAP_CONTENT,
							LayoutParams.WRAP_CONTENT);
					timeLayoutParam.topMargin = 7;
					timeText.setLayoutParams(timeLayoutParam);
					timeText.setText(getString(R.string.favorable_end_time)
							+ favorableEndTime);
					timeText.setTextColor(Color.rgb(127, 157, 227));
					layout.addView(timeText);

					favorableInfosLayout.addView(layout);
				}
			}

			// 商户介绍
			TextView merchantIntroduceText = (TextView) branchDetail
					.findViewById(R.id.merchantIntroduceText);
			merchantIntroduceText.setText(merchantIntroduce);

			// 特色
			TextView merchantSpecialText = (TextView) branchDetail
					.findViewById(R.id.merchantSpecialText);
			merchantSpecialText.setText(merchantSpecial);

			// 地区
			TextView merchantRegionText = (TextView) branchDetail
					.findViewById(R.id.merchantRegionText);
			merchantRegionText.setText(merchantRegion);

			// 交通
			TextView merchantTrafficText = (TextView) branchDetail
					.findViewById(R.id.merchantTrafficText);
			merchantTrafficText.setText(merchantTraffic);

			// 停车位
			TextView merchantParkingText = (TextView) branchDetail
					.findViewById(R.id.merchantParkingText);
			merchantParkingText.setText(merchantParking);

			LocationServiceActivity.this.runOnUiThread(new Runnable() {

				@Override
				public void run() {
					// 1.移除右侧View
					rightLayout.removeAllViews();

					rightLayout.addView(branchDetail);
				}
			});

			// 把当前页面放至栈
			pushPageToStack(branchDetail, stackKey);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return branchCoord;
	}

	@Override
	public void finish() {
		super.finish();
		BankcommApplication.getInstance().removeActivity(this);
	}

}
